<template>
  <div>
    <a-card :bordered="false">
      <f-search-form @searchHandler="searchHandler">
        <f-search-form-item label="单号" name="productName"/>
        <f-search-form-item label="商品名称" name="brandName"/>
        <f-search-form-item label="创建日期" name="rangeDate" type="range" slot="advanced"/>
      </f-search-form>
      <f-table ref="table" size="default" rowKey="afterServiceId" :scroll="scroll"  :columns="columns" handler="shopAfterServiceListHandler" :operator="operator" :params="queryParam" :api="api.afterService">
        <span slot="productTitle" slot-scope="text, record, index">
             <f-elipsis :text="record.productTitle"></f-elipsis>
        </span>
        <span slot="serviceType" slot-scope="text, record, index">
          <a-tag color="pink">{{record.serviceType}}</a-tag>
        </span>
        <span slot="serviceType" slot-scope="text, record, index">
            <a-tag color="pink" v-if="text==1">维修</a-tag>
            <a-tag color="#108ee9" v-if="text==2">退货</a-tag>
        </span>
        <span slot="productImages" slot-scope="text, record, index">
          <img v-lazy="record.productImages" v-viewer class="radius-img">
        </span>

        <span slot="serviceState" slot-scope="text, record, index">
            <a-tag color="pink" v-if="text==0">未审核</a-tag>
            <a-tag color="#108ee9" v-if="text==1">已审核</a-tag>

        </span>

        <span slot="action" slot-scope="text, record">
          <template>
            <a href="javascript:;" @click="$refs.modal.handleShow(record)" v-if="record.serviceState==0">审核</a>
            <a-divider type="vertical"/>
          </template>
          <a-dropdown>
            <a class="ant-dropdown-link">
              更多 <a-icon type="down"/>
            </a>
            <a-menu slot="overlay">
              <a-menu-item v-if="$auth('table.delete')">
                <a href="javascript:;" @click="$refs.table.remove(record.afterServiceId)">删除</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </f-table>
      <after-service-drawer ref="modal"></after-service-drawer>
    </a-card>
  </div>
</template>

<script>
  import AfterServiceDrawer from './afterservice_drawer'
  import Ellipsis from '../../../../components/Ellipsis/Ellipsis'

  export default {
    name: 'TableList',
    components: { AfterServiceDrawer },
    data() {
      return {
        //列表初始化查询参数
        queryParam: {},
        scroll: { x: 1450 },
        firstCategory: [],
        onLineState: [{ value: '2', label: '已下架' }, { value: '3', label: '违规下架' }],
        skuList: [],
        // 表头
        columns: [
          {
            title: '#',
            align: 'center',
            customRender: (text, record, index) => index + 1
          },{
            title: '商品图片',
            align: 'center',
            dataIndex: 'coverImage',
            scopedSlots: { customRender: 'productImages' }
          },
          {
            title: '单号',
            dataIndex: 'orderNo'
          },
          {
            title: '商品名称',
            dataIndex: 'productTitle',
            scopedSlots: { customRender: 'productTitle' }
          },
          {
            title: '售后类型',
            align: 'center',
            dataIndex: 'serviceType',
            scopedSlots: { customRender: 'serviceType' }
          },
          {
            title: '服务单号',
            align: 'center',
            dataIndex: 'serviceNo'
          },
          {
            title: '申请日期',
            dataIndex: 'createTime',
            sorter: true
          },
          {
            title: '审核状态',
            align: 'center',
            dataIndex: 'serviceState',
            scopedSlots: { customRender: 'serviceState' }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed: 'right',
            scopedSlots: { customRender: 'action' }
          }
        ],
        //操作按钮
        operator: [

          {
            name: '删除',
            icon: 'delete',
            batch: true,
            handler: function(table) {
              table.remove()
            }
          }
        ]
      }
    },
    computed: {},
    methods: {
      getText: function(value) {
        if (value == 1) {
          return '已上架'
        }
        if (value == 2) {
          return '已下架'
        }
        if (value == 3) {
          return '违规下架'
        }
      },
      getImages(sku) {
        let images = sku.images
        if (images != '' && images.indexOf('[{') > -1) {
          let obj = JSON.parse(images)
          if (obj && obj.length > 0) {
            return obj[0].url
          }
        }
        return images
      },
      setStatus(value, record) {
        this.http.post(this, {
          url: this.api.product.setOnLineState,
          data: {
            ids: record.productId,
            onlineState: value
          },
          success(me, data) {
            record.onLineState = data
          }
        })
      },
      setRecommend(check, record) {
        this.http.post(this, {
          url: this.api.product.setRecommend,
          data: {
            ids: record.productId,
            recommend: Number(check)
          },
          success(me, data) {
            record.recommend = data
          }
        })
      },
      onExpand(expanded, record) {
        if (expanded) {
          this.skuList = []
          this.http.get(this, {
            url: this.api.product.getSkuList,
            data: {
              params: {
                productId: record.productId
              }
            },
            success: function(me, data) {
              me.skuList = data
            }
          })
        }
      }
    },
    created() {

    }
  }
</script>
<style scoped lang="less" rel="stylesheet/less">

  .single-item {
    text-align: center;
    float: left;
    margin-right: 8px;
    border: 1px solid #E1E6F0;
    width: 180px;
    height: 180px;
    padding: 10px;
    cursor: pointer;
  }

  .single-item .hold-img {
    padding: 5px;
  }


  .single-item p {
    margin: 0px;
    width: 140px;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .single-item .spec-title {
    margin-top: 5px;

    color: #00A0E9;
  }

  .single-item .row-term p {
    width: 160px;
    text-align: left;
  }

  .product-title {
    display: inline-block;
    text-align: left;
    padding-left: 20px;
  }

  .row-title {
    display: inline-block;
    text-align: center;
    padding-left: 20px;
  }

</style>
